package demo4;

/**
 * Author：毕龙
 * Date: 2024/5/17 9:43
 */
public class TestThreadSelf1 {
    public static void main(String[] args)  {
        //创建StringBuilder
        StringBuilder sb = new StringBuilder();
        //创建线程
        Thread t1 = new Thread("子枭"){
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    sb.append(currentThread().getName()+"\t"+i+"\n");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        Thread t2 = new Thread("王伟"){
            @Override
            public void run() {
                for (int i = 9999; i < 19999; i++) {
                    sb.append(currentThread().getName()+"\t"+i+"\n");
                    System.out.println(sb);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        //启动线程
        t1.start();
        t2.start();


    }



}
